﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel;
using DoAnWeb.DTO;

namespace DoAnWeb.DAO
{
    public class LoaiSanPhamDAO
    {
        DataProvider dp = new DataProvider();

        public BindingList<LoaiSanPhamDTO> GetList()
        {
            if (dp.OpenConnect())
            {
                DataTable dt = dp.SqlExcuteQuery("uproc_GetList_LoaiSanPham", null);
                dp.CloseConnect();
                BindingList<LoaiSanPhamDTO> List = new BindingList<LoaiSanPhamDTO>();
                foreach (DataRow row in dt.Rows)
                {
                    LoaiSanPhamDTO DTO = new LoaiSanPhamDTO();
                    DTO.MaLoaiSanPham = int.Parse(row["MaLoaiSanPham"].ToString());
                    DTO.TenLoaiSanPham = row["TenLoaiSanPham"].ToString();
                    List.Add(DTO);
                }
                return List;
            }
            return null;
        }

        public BindingList<LoaiSanPhamDTO> GetFromID(int _Ma)
        {
            if (dp.OpenConnect())
            {
                SqlParameter[] sqlParameter = 
                { 
                    new SqlParameter("@MaLoaiSanPham", _Ma) 
                };
                DataTable dt = dp.SqlExcuteQuery("uproc_GetFromID_LoaiSanPham", sqlParameter);
                dp.CloseConnect();
                BindingList<LoaiSanPhamDTO> List = new BindingList<LoaiSanPhamDTO>();
                foreach (DataRow row in dt.Rows)
                {
                    LoaiSanPhamDTO DTO = new LoaiSanPhamDTO();
                    DTO.MaLoaiSanPham = int.Parse(row["MaLoaiSanPham"].ToString());
                    DTO.TenLoaiSanPham = row["TenLoaiSanPham"].ToString();
                    List.Add(DTO);
                }
                return List;
            }
            return null;
        }

    }
}